package com.meilele.controller.guoziyang;


import com.meilele.biz.guoziyang.SecDetailBusiness;
import com.meilele.biz.guoziyang.SecShowImageBusiness;
import com.meilele.biz.guoziyang.SeclaberBusiness;
import com.meilele.entity.guoziyang.SecDetail;
import com.meilele.entity.guoziyang.Seclaber;
import com.meilele.entity.zhengchao.AjaxMsgModel;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/detail")
public class DetailController {
    int[] secShuZu = new int[10];

    @Resource
    private SecDetailBusiness secDetailBusiness;

    @Resource
    private SeclaberBusiness seclaberBusiness;
    @Resource
    private SecShowImageBusiness secShowImageBusiness;

    @RequestMapping("/list")
    public String findAll(Model model) {
        List<SecDetail> secDetailList = secDetailBusiness.findAll();
        model.addAttribute("detailList", secDetailList);
        return "second/second";
    }

    @RequestMapping("/test")
    public String findAll2(int photoname, Model model) {
        List<Seclaber> seclaberList = seclaberBusiness.findAll();
        model.addAttribute("lable", seclaberList);
        List<SecDetail> secDetailList = secDetailBusiness.findAll1(photoname);
        System.out.print(secDetailList);
        model.addAttribute("detailList", secDetailList);
        return "second/second";
    }

    @RequestMapping("/detailList")
    public String findImageDetail() {


        return "second/detail";
    }
    @ResponseBody
    @RequestMapping("/delet")
    public AjaxMsgModel deleteDetail(int caseId) {
        secDetailBusiness.deleteDetail(caseId);
        secShowImageBusiness.deleteShow(caseId);
        return new AjaxMsgModel("200","删除成功","sdogzy","","closeCurrent","");

    }

    @RequestMapping("/preUpdate")
    public String preUpdate(int caseId, Model model) {
        List<Seclaber> seclaberList = seclaberBusiness.findAll();
        model.addAttribute("lable", seclaberList);

        List<Seclaber> seclaberList1 = secDetailBusiness.findById(caseId);
//   for (int i = 0;i<seclaberList1.size() ; i++){
//       secShuZu[i]=seclaberList1.get(i).getStyleId();
//   }
        List<Integer> module_ids = new ArrayList<Integer>();
        for (Seclaber module : seclaberList1) {
            module_ids.add(module.getStyleId());
        }
        model.addAttribute("secShuZu", module_ids);
        SecDetail secDetail = secDetailBusiness.selectById(caseId);
        model.addAttribute("secDetail", secDetail);

        return "second/demo_page5";
    }
    @ResponseBody
    @RequestMapping("/update")
    public AjaxMsgModel update(@Param("lable") int[] laber,SecDetail detail){
        System.out.println("laber"+laber+"---------------"+"detail"+detail);
               secDetailBusiness.updateDetail(detail);
               secShowImageBusiness.deleteDeLa(detail.getStyleId());
        for (int i = 0; i < laber.length; i++) {

            int laberId = laber[i];
            int ww = secDetailBusiness.saveDeLa(laberId, detail.getStyleId());
            System.out.println(ww);
        }
        return new AjaxMsgModel("200","删除成功","sdogzy","","closeCurrent","");

    }

}

